package com.voice.call.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.voice.call.common.Const;
import com.voice.call.common.ConstLang;
import com.voice.call.common.Result;
import com.voice.call.common.ResultEnum;
import com.voice.call.service.NewsService;
import com.voice.call.utils.JSONUtil;
import com.voice.call.version.ApiVersion;


//新闻管理
@RestController
@RequestMapping("/api/{version}/news/")
public class NewsController {

	private final Logger log = LoggerFactory.getLogger(NewsController.class);
	
	@Resource
	private NewsService newsService;
	
	@ResponseBody
	@ApiVersion(1)
	@RequestMapping(value = "list", method = RequestMethod.POST, produces = Const.JSON_UTF8)
	public Result list(@RequestBody Map<String, Object> params) {
		
		//log.debug("参数:{}",JSONUtil.objectToJson(params));
		String lang = ConstLang.getLang(params);
		// 判断入参
		if (null == params ||  params.get("page") == null || params.get("pagesize") == null) {
			//log.error(ResultEnum.PARAM_ERROR.getMsg());
			return new Result(ResultEnum.PARAM_ERROR,lang);
		}
		
		//params.get("lang") == null || params.get("country") == null || params.get("category") == null ||
		String country = "";
		if(params.get("country")!=null){
			country = params.get("country").toString();
		}
		
		String category = "";
		if(params.get("category")!=null){
			category = params.get("category").toString();
		}
		Integer page = Integer.valueOf(params.get("page").toString());
		Integer pagesize = Integer.valueOf(params.get("pagesize").toString());
		
		//return newsService.getNewsPageList(lang,country,category, page, pagesize);
		return newsService.getNewsPageList(Const.LANGUAGE,country,category, page, pagesize);
	}
}
